import unittest,time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium import webdriver
from zuoye.a3mall_db import a3mall
from ddt import ddt,file_data
@ddt
class A3mall(unittest.TestCase):
    def setUp(self):
        self.db=a3mall(host='10.59.9.12', user='root', password='yidong666', databases='a3mall')
        self.driver=webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('http://10.59.9.12:7001/')

    def tearDown(self):
        time.sleep(5)
        self.driver.quit()

    @file_data('data.yaml')
    def test_a3mall_login_01(self,username,password):
        self.driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        self.driver.find_element(By.NAME,'username').send_keys(username)
        self.driver.find_element(By.NAME,'password').send_keys(password)
        time.sleep(8)
        self.driver.find_element(By.CLASS_NAME,'finish-btn').click()
        time.sleep(5)






    # def test_a3mall_02(self):
    #     self.test_a3mall_login_01()
    #     dy1=self.driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').text
    #     print(dy1)
    #     shujudy = self.db.select('select username from mall_users where nickname="胡杰"')[0]
    #     assert "欢迎回来，",+shujudy[0]==dy1
    #     print("数据库1：",shujudy[0])
    #     time.sleep(2)
    #     dy2=self.driver.find_element(By.XPATH,'//a[@href="/home/ucenter/index.html"]').text
    #     print(dy2)
    #     time.sleep(2)
    #     dy3=self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]/span').text
    #     dy31=dy3.replace('¥ ','')
    #     print(dy31)
    #     shujudy1 = self.db.select('select amount from mall_users where nickname="胡杰"')[0]
    #     assert str(shujudy1[0])==dy31
    #     print("数据库2：",shujudy1)
    #     time.sleep(2)
    #     self.driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
    #     a=self.driver.find_element(By.CLASS_NAME,'search-input')
    #     a.send_keys('宋牌')
    #     a.send_keys(Keys.ENTER)
    #     time.sleep(1)
    #     self.driver.find_element(By.XPATH,'//img[@src="/uploads/images/20250620/67e1bd127f10d17039e45464df4c460a.jpg"]').click()
    #     time.sleep(1)
    #     dy4=self.driver.find_element(By.XPATH,'//a[@href="/home/goods/view.html?id=40"]').text
    #     print(dy4)
    #     time.sleep(2)
    #     self.driver.find_element(By.ID,'buy-cart').click()
    #     dy5=self.driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
    #     print(dy5)
    #     time.sleep(2)
    #     self.driver.find_element(By.ID,'address-801').click()
    #     self.driver.find_element(By.ID,'order-button').click()
    #     dy6=self.driver.find_element(By.XPATH,'/html/body/div[4]/div[1]/a[2]').text
    #     print(dy6)
    #     time.sleep(2)
    #     self.driver.find_element(By.XPATH,'/html/body/div[4]/div[3]/p/a').click()
    #
    #     time.sleep(5)


if __name__ == '__main__':
    unittest.main()

